package kr.hkit.powerjava.chapter24.work1;

import java.io.Serializable;

public class Student implements Serializable, Comparable<Student>{	//버전 비교
	private int stdNum;
	private String stdName;
	private int kor;
	private int eng;
	private int math;
	
	public Student(int stdNum, String stdName) {
		this.stdNum = stdNum;
		this.stdName = stdName;
	}
	
	public Student(int stdNum, String stdName, int kor, int eng, int math) {
		this.stdNum = stdNum;
		this.stdName = stdName;
		this.kor = kor;
		this.eng = eng;
		this.math = math;
	}

	public int getStdNum() {
		return stdNum;
	}

	public void setStdNum(int stdNum) {
		this.stdNum = stdNum;
	}

	public String getStdName() {
		return stdName;
	}

	public void setStdName(String stdName) {
		this.stdName = stdName;
	}

	public int getKor() {
		return kor;
	}

	public void setKor(int kor) {
		this.kor = kor;
	}

	public int getEng() {
		return eng;
	}

	public void setEng(int eng) {
		this.eng = eng;
	}

	public int getMath() {
		return math;
	}

	public void setMath(int math) {
		this.math = math;
	}
	
	public int totalScore() {
		return kor + eng + math;
	}
	
	public double totalAvg() {
		return totalScore() / 3.0;
	}

	@Override
	public String toString() {
		return String
				.format("%3s\t%5s\t%3s\t%3s\t%3s\t%3s\t%6.3f",
						stdNum, stdName, kor, eng, math,totalScore(), totalAvg());
	}

	@Override
	public boolean equals(Object obj) { 
		Student temp = (Student) obj;
		if(obj instanceof Student) {
			return stdNum == temp.stdNum && stdName.equals(temp.stdName);
		} else {
			return false;
		}
	}

	@Override
	public int compareTo(Student o) {	
		return stdNum - o.stdNum;	//학번으로 정렬
	}
}